//
//  ZCCustomConcaveView.m
//  ZhaoCaiMao
//
//  Created by 谢英泽 on 2017/3/21.
//  Copyright © 2017年 谢英泽. All rights reserved.
//

#import "CustomConcaveView.h"

@interface CustomConcaveView ()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation CustomConcaveView

- (instancetype)initWith:(CGSize)size {
    self = [super init];
    if (self) {
        _width = size.width;
        _height = size.height;
        self.backgroundColor = kCOLOR_clear;
        [self initSubView];
    }
    return self;
}

#pragma mark - 内部方法

- (void)initSubView {
    [self.superview layoutIfNeeded];
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    [path moveToPoint:CGPointMake(0, 0)];
    [path addArcWithCenter:CGPointMake(0, 10) radius:10 startAngle:RADIANS_TO_DEGREES(-90) endAngle:RADIANS_TO_DEGREES(90) clockwise:YES];
    [path addLineToPoint:CGPointMake(_width, 20)];
    [path addArcWithCenter:CGPointMake(_width, 10) radius:10 startAngle:RADIANS_TO_DEGREES(90) endAngle:RADIANS_TO_DEGREES(270) clockwise:YES];
    [path moveToPoint:CGPointMake(_width, 0)];
    [path addLineToPoint:CGPointMake(0, 0)];
    
    path.lineWidth = 1.f;
    
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.strokeColor = kCOLOR_white.CGColor;
    layer.fillColor = kCOLOR_white.CGColor;
    layer.path = path.CGPath;
    [self.layer addSublayer:layer];
    
    //添加曲线
    UIView *lineView = [UIView new];
    self.lineView = lineView;
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(_height/2));
        make.right.equalTo(@(-_height/2));
        make.centerY.equalTo(@0);
        make.height.equalTo(@2);
    }];
    
    CAShapeLayer *lineLayer = [CAShapeLayer layerWithFrame:CGRectMake(0, 0.5, _width - _height, 1)];
    [lineLayer setStrokeColor:kCOLOR_RGBValue(0xe1e1e1).CGColor];
    [lineView.layer addSublayer:lineLayer];
    lineView.hidden = NO;
}

#pragma mark - 点击事件


#pragma mark - 外部方法


#pragma mark - Setter && Getter

- (void)setShowDottedLine:(BOOL)showDottedLine {
    _showDottedLine = showDottedLine;
    
    if (!showDottedLine) {
        self.lineView.hidden = YES;
    }
}



@end
